﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using THO7AlgorithmBase;

namespace THO7AlgoritmTimerApplication
{
    public partial class MainForm : Form
    {
        Bitmap InputImage;
        public MainForm()
        {
            InitializeComponent();
        }

        private void loadButton_Click(object sender, EventArgs e)
        {
            openImage();
        }

        private void openImage() {
            OpenFileDialog oFD = new OpenFileDialog();
            // DIT IS VERVELEND:
            //oFD.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
            oFD.Filter = "Image Files(*.BMP;*.JPG;*.JPEG;*.PNG;)|*.BMP;*.JPG;*.JPEG;*.PNG;";
            oFD.FilterIndex = 1;
            oFD.RestoreDirectory = true;
            if (oFD.ShowDialog() == DialogResult.OK) {
                String CurrentFileName = Path.GetFullPath(oFD.FileName);
                InputImage = new Bitmap(CurrentFileName);
                InputPictureBox.Image = InputImage;
            }
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void ClearButton_Click(object sender, EventArgs e)
        {
            InfoLabel.Text = "";
        }

        private void EnableAllInputs(bool state)
        {
            //openPictureToolStripMenuItem.Enabled = state;
            InputPictureBox.Enabled = state;
        }
        private void OCRstart(object sender, EventArgs e) {
            OCR ocr = new OCR("OCR");
            ocr.OCR_learn(InputImage, inputmask1.Text);
            ocr.OCR_learn(InputImage, inputmask1.Text);
            ocr.OCR_learn(InputImage, inputmask1.Text);
        }

        private void recognize(object sender, EventArgs e)
        {
            String[] volgorde = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" , "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
            OCR ocr = new OCR("OCR");
            double[] percentage = new double[36]; 
            percentage = ocr.DoOCR(InputImage);
            double k = 0;
            int max = 0;
            for (int i = 0; i < percentage.Length; i++) {
                if (percentage[i] > k) {
                    k = percentage[i];
                    max = i;
                }
            }
            InfoLabel.Text ="";
            for (int i = 0; i < percentage.Length; i++) {
                InfoLabel.Text += "letter : " + volgorde[i] + "     percentage: " + percentage[i] + "%\n";
            }
            if (!(k < 40)) {
                InfoLabel.Text += "\nDe waarschijnlijkste is : " + volgorde[max] +"\nMet percentage : " + percentage[max] + "%\n";
            } else {
                InfoLabel.Text += "\nEr is geen teken herkend";
            }
        }
    }
}
